﻿<Window x:Class="GraphicScript.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:gs="clr-namespace:GraphicScript"
        Title="GraphicScript: a demo host for LENS compiler" Height="768" Width="1024" MinWidth="640" MinHeight="480"
        d:DataContext="{d:DesignInstance gs:MainWindow}"
        mc:Ignorable="d">
    <Window.Resources>
        
        <gs:BoolToVisibilityConverter x:Key="ShowIfTrue" />
        <gs:BoolToVisibilityConverter IsInverted="True" x:Key="ShowIfFalse" />
        
        <Style TargetType="TextBox" x:Key="EditorStyle">
            <Setter Property="Background" Value="#171E1F" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="FontFamily" Value="Consolas" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="AcceptsReturn" Value="True" />
            <Setter Property="AcceptsTab" Value="True" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TextBox">
                        <Border Name="Bd" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"
                                SnapsToDevicePixels="true">
                            <ScrollViewer Name="PART_ContentHost" Background="{TemplateBinding Background}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="PART_ContentHost" Property="Opacity" Value="0.3" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <Style TargetType="Button" x:Key="ActionButtonStyle">
            <Setter Property="Margin" Value="10,10,0,0" />
            <Setter Property="Padding" Value="8,4" />
            <Setter Property="Width" Value="90" />
        </Style>
        
        <Style TargetType="TextBlock" x:Key="StatusStyle">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Status}" Value="{x:Static gs:Status.Ready}">
                    <Setter Property="Text" Value="Type the script and hit F5 to execute." />
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="{x:Static gs:Status.Error}">
                    <Setter Property="Foreground" Value="DarkRed" />
                    <Setter Property="Text" Value="{Binding ErrorMessage}" />
                    <Setter Property="FontWeight" Value="Bold" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="{x:Static gs:Status.Compiling}">
                    <Setter Property="Foreground" Value="DarkBlue" />
                    <Setter Property="Text" Value="Compiling..." />
                    <Setter Property="FontWeight" Value="Bold" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="{x:Static gs:Status.Success}">
                    <Setter Property="Foreground" Value="DarkGreen" />
                    <Setter Property="Text" Value="Compiled successfully, executing. Hit Esc to return to edit mode." />
                    <Setter Property="FontWeight" Value="Bold" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid SnapsToDevicePixels="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" MinWidth="250" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            
            <Button Style="{StaticResource ActionButtonStyle}" Content="Load" Command="{Binding LoadCommand}" />
            
            <Button Grid.Column="2" Style="{StaticResource ActionButtonStyle}" Content="Run" Command="{Binding RunCommand}"
                    Visibility="{Binding EditEnabled, Converter={StaticResource ShowIfTrue}}" />
            <Button Grid.Column="2" Style="{StaticResource ActionButtonStyle}" Content="Stop" Command="{Binding StopCommand}"
                    Visibility="{Binding EditEnabled, Converter={StaticResource ShowIfFalse}}" />
        </Grid>
        
        <Border Grid.Row="1" Margin="10,10,0,10" BorderBrush="Black" BorderThickness="1">
            <TextBox x:Name="CodeEditor" Style="{StaticResource EditorStyle}" IsEnabled="{Binding EditEnabled, Mode=OneWay}" Text="{Binding Code, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        </Border>
        
        <GridSplitter Grid.Column="1" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Stretch" Width="6" ShowsPreview="True" ResizeBehavior="PreviousAndNext" />

        <Border Grid.Column="2" Grid.RowSpan="2" BorderBrush="Black" BorderThickness="1" Margin="0,10,10,10">
            <Canvas x:Name="Canvas" ClipToBounds="True" />
        </Border>
        
        <TextBlock Grid.Row="3" Grid.ColumnSpan="3" Style="{StaticResource StatusStyle}" Margin="10,0,10,10" />
    </Grid>
</Window>
